<?php
class BaseAction extends Action
{
    public function MTASK()
    {
        $model = new Model();
        return $model->db(2, 'mysql://root:227705@localhost/task');
    }

    /**
     * 获取IP地址
     * @param string $ip
     * @return array
     */
    public function getIpDetail($ip = null)
    {
        $ipDetail = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip);
        $ipArray = json_decode($ipDetail);
        return $this->getObjectVarsFinal($ipArray);
    }

    /**
     * object to array
     * @param object $obj
     * @author Ice <iceinto@mallog.com.cn>
     */
    public function getObjectVarsFinal ($obj)
    {
        if (is_object($obj)) {
            $obj = get_object_vars($obj);
        }

        if (is_array($obj)) {
            foreach ($obj as $key => $value) {
                $obj[$key] = $this->getObjectVarsFinal($value);
            }
        }
        return $obj;
    }
}

?>